/*
 * $Id: fsm.h,v 1.13 2005-12-05 15:11:29 bacon Exp $
 */

#ifndef _XP_UTL_FSM_H_
#define _XP_UTL_FMS_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/sysapi.h>

enum
{
	XP_FSM_MKDIR_PARENTS = 1
};

enum
{
	XP_FSM_RMDIR_PARENTS = 1
};

enum 
{
	XP_FSM_ENOERR,
	XP_FSM_ENOMEM, /* out of memory */
	XP_FSM_EINVAL, /* wrong/invalid value (path name, etc) */
	XP_FSM_EACCES, /* access denied */
	XP_FSM_EEXIST, /* file/directory exists */
	XP_FSM_ENOSRC, /* no source */
	XP_FSM_ESAMFL, /* same file */
	XP_FSM_ERENAM, /* failed to rename a file */
	XP_FSM_EUNLNK, /* failed to unlink a file */
	XP_FSM_EMKDIR, /* failed to create a directory */
	XP_FSM_ECANCL  /* cancelled */
};

/*
 * TYPEDEF: xp_fsm_confirmer_t
 *   Defines a confirmer type
 */
typedef int (*xp_fsm_confirmer_t) (int cmd, void* arg, const xp_char_t* file);

enum 
{
	XP_FSM_CONFIRM_OVERWRITE
};

struct xp_fsm_t
{
	int errnum;

	xp_fsm_confirmer_t confirmer;
	void* confirmer_arg;

	xp_bool_t __dynamic;
};

typedef struct xp_fsm_t xp_fsm_t;

#ifdef __cplusplus
extern "C" {
#endif

/* 
 * FUNCTION: xp_fsm_open
 */
xp_fsm_t* xp_fsm_open (xp_fsm_t* fsm);

/*
 * FUNCTION: xp_fsm_close
 */
void xp_fsm_close (xp_fsm_t* fsm);

/*
 * FUNCTION: xp_fsm_error
 */
int xp_fsm_error (xp_fsm_t* fsm, xp_char_t* errbuf, xp_size_t size);

/*
 * FUNCTION: xp_fsm_attach_confirmer
 */
void xp_fsm_attach_confirmer (
	xp_fsm_t* fsm, xp_fsm_confirmer_t confirmer, void* arg);

/*
 * FUNCTION: xp_fsm_detach_confirmer
 */
void xp_fsm_detach_confirmer (xp_fsm_t* fsm);

/*
 * FUNCTION: xp_fsm_copy
 */
int xp_fsm_copy (xp_fsm_t* fsm, const xp_char_t* src, const xp_char_t* tgt);

/*
 * FUNCTION: xp_fsm_move
 */
int xp_fsm_move (xp_fsm_t* fsm, const xp_char_t* src, const xp_char_t* tgt);

/*
 * FUNCTION: xp_fsm_remove
 */
int xp_fsm_remove ();

/*
 * FUNCTION: xp_fsm_link
 */
int xp_fsm_link ();

/* 
 * FUNCTION: xp_fsm_mkdir
 */
int xp_fsm_mkdir (xp_fsm_t* fsm, const xp_char_t* path, xp_mode_t mode, int flags);

/* 
 * FUNCTION: xp_fsm_rmdir
 */
int xp_fsm_rmdir (xp_fsm_t* fsm, const xp_char_t* path, int flags);


#ifdef __cplusplus
}
#endif

#endif
